package cn.lizemin.state.version1.entity;

/**
 * @author lzm
 * @version 1.0
 * @description: 存在的缺陷：
 *  *  每次改变状态都需要new出一个新的状态对象，非常浪费，所以状态最好设置成单例的，
 *  *  因此还需要用单例模式改造下状态类
 * @date 2022/4/25 10:07
 */
public class Red implements State {
    private static final Red redLight = new Red();

    private Red(){}

    public static Red getInstance() {
        return redLight;
    }

    @Override
    public void switchToGreen(TrafficLight trafficLight) {
        trafficLight.setState(Green.getInstance());
        System.out.println("绿灯亮60s");
    }

    @Override
    public void switchToYellow(TrafficLight trafficLight) {
        trafficLight.setState(Yellow.getInstance());
        System.out.println("黄灯亮...");
    }

    @Override
    public void switchToRed(TrafficLight trafficLight) {
        System.out.println("ERROR！当前状态已经是红灯，无须再切换");
    }
}
